const multer = require("multer")
const { UploadError } = require("../utils/errors")
const { uploading, formatResponse } = require("../utils/tool")

module.exports.uploadFileService = async function(){
    uploading.single("file")(req,res,function(err){
        if(err instanceof multer.MulterError){
          next(new UploadError("上传文件失败,请检查文件的大小,控制在2MB以内"))
        }else{
            const resp = {
                msg:"上传文件成功",
                path:"/static/uploads"
            }
            res.send(formatResponse(0,"",resp.path))
        }
    })
}